<?php
namespace app\api\controller\haipi;

use app\api\service\OrderService;
use app\api\service\VpayService;
use app\common\controller\Frontend;
use think\facade\Log;

class Vpay extends Frontend
{
    protected array $noNeedLogin = ['*'];

    protected array $noNeedPermission = ['*'];


    public function getClient(VpayService $vpayService){
        $data = $vpayService->queryAvailableClient();
        $this->success('获取成功', $data);
    }

    /**
     * 
     * 支付通知回调
     * @return void
     */
    public function notify(OrderService $orderService, VpayService $vpayService): string{
        if($this->request->isGet()){
            $this->error('非法请求');
        }
        $data = $this->request->post();
        try{
            $vpayService->checkSign($data);
            $orderService->callback($data['trade_no'],  $data['pay_time']);
        }catch (\Exception $e){
            Log::error($e->getMessage());
            die('error');
        }
        die('success');
    }
}